/*
 * All header file for c language MUST be include : in extern "C" { }
 */
extern "C" {
#include "../src/uni_audio_player.c"
}

/*
 * Before running this test case, remove keyword "static" before above functions
 */
static int _audio_write_stub(uni_u32 frames) {
  printf("stub %s\n", __FUNCTION__);
  int time = rand() % 20;
  uni_msleep(time);
  if (time % 20 == 0) {
    return -1;
  }
  return frames;
}

static Result _audioout_init_stub(AudioPlayerParam *param) {
  printf("stub %s\n", __FUNCTION__);
  return E_OK;
}

static void _audioout_final_stub(void) {
  printf("stub %s\n", __FUNCTION__);
}

static void _player_start_internal_stub(void) {
  printf("stub %s\n", __FUNCTION__);
}

static void _player_stop_internal_stub(void) {
  printf("stub %s\n", __FUNCTION__);
}
/*
 * H2UNIT is a unit test Suite, which contains several test cases.
 */
H2UNIT(audio_player) {
  /*
   * setup() will be executed before every test case belong to this suite.
   * Typically it is used to prepare preconditions.
   */
  void setup() {
    H2STUB(_audio_write, _audio_write_stub);
    H2STUB(_audioout_init, _audioout_init_stub);
    H2STUB(_audioout_final, _audioout_final_stub);
    H2STUB(_player_start_internal, _player_start_internal_stub);
    H2STUB(_player_stop_internal, _player_stop_internal_stub);
    AudioPlayerInit(NULL);
    srand((int)time(0));
  }

  /*
   * teardown() will be executed after every test case belong to this suite.
   * whatever test case passed or failed.
   * Typically it is used to release resource.
   */
  void teardown() {
    AudioPlayerFinal();
  }
};

/*
 * testcase to test EventRouteProcess function.
 * include normal and abnormal conditionis.
 */
H2CASE(audio_player, "logic test") {
  Result ret;
  int i;
  int time;
  for (i = 0; i < 10; i++) {
    LOGT("test", "round %d ---------------------------------------", i)
    LOGT("test", "before playing");
    ret = AudioPlayerStart(NULL);
    LOGT("test", "after playing %d", ret);
    time =rand() % 200;
    uni_msleep(time);
    LOGT("test", "before stop");
    ret = AudioPlayerStop();
    LOGT("test", "after stop %d", ret);
    time =rand() % 10;
    uni_msleep(time);
  }
}


